<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        (function () {
            /*
              创建symbol不会相等       
            */
            const _test = Symbol('test')
            const _test2 = Symbol('test2')
            console.log(_test === _test2, _test == _test2)//
        })()
    </script>

    <script>
            (function () {
                /*
                  Symbol.for() 创建相等的      
                */
                let symbol1 = Symbol.for('你好')
                let symbol2 = Symbol.for('你好')
                console.log(symbol1 === symbol2)//true
            })()
    </script>

    <script>

            (function () {
                const _test = Symbol('test')
                const _test2 = Symbol('test2')
                const obj = {
                    key: '1'
                }
                obj[_test] = '测试'
                obj[_test2] = '测试2'
                console.log(obj)
                console.log(obj[Symbol('test')])//无法获取
                const arr = Object.getOwnPropertySymbols(obj)// [Symbol(test), Symbol(test2)]
                const [symbol, symbol2] = Object.getOwnPropertySymbols(obj)// [Symbol(test), Symbol(test2)]
                console.log(symbol, symbol2)//Symbol(test) Symbol(test2)
                console.log(arr[0])//Symbol(test)
                console.log(obj[arr[0]])//测试
                console.log(obj[arr[1]])//测试2
            })()
    </script>

    <script>
            // 配合 of 循环 
            (function () {
                const obj = {
                    [Symbol.iterator]: function* () {
                        let a = 1;
                        let b = 1;
                        let temp;

                        yield b;

                        while (true) {
                            temp = a;
                            a = a + b;
                            b = temp;
                            yield b;
                        }
                    }
                };
                for (const x of obj) {
                    if (x >= 100) {
                        break;
                    }
                }
            })()
    </script>

    <script>
            /*
                执行 instanceof    实际内部会调用Foo[Symbol.hasInstance](param)
            */
            (function () {
                class Person {
                    static [Symbol.hasInstance](param) {
                        console.log(param)  //{}
                        return true  //return true 返回true  false  返回false  未填写返回false
                    }
                }
                let obj = {
                    value: 2
                }
                console.log(obj instanceof Person) //true
            })()
    </script>
</body>

</html>